package com.qf.lanzhou.shop.api.controller;

import com.qf.lanzhou.shop.api.exceptions.BaseExceptions;
import com.qf.lanzhou.shop.api.service.SerialService;
import com.qf.lanzhou.shop.pojo.entity.Serial;
import com.qf.lanzhou.shop.pojo.entity.User;
import com.qf.lanzhou.shop.pojo.qo.SerialQo;
import com.qf.lanzhou.shop.pojo.vo.BaseRespVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

/**
 * @author Yeach-chen
 * @ClassName SerialsController
 */
@Controller
public class SerialsController extends BaseController {
    @Autowired
    private SerialService serialService;
    @ResponseBody
    @RequestMapping("/get_serial")
    public BaseRespVO getSerials(HttpServletRequest req) throws ParseException {
        User user = (User) req.getSession().getAttribute("user");
        if (null==user){
            throw new BaseExceptions(301,"11");
        }
        List<Serial> serials = serialService.getSerial(user.getId());
        return convertSuccessResult(serials);
    }
    @ResponseBody
    @RequestMapping("/delete_serials")
    public BaseRespVO deleteSerials(Long id) throws ParseException {
        int result = serialService.deleteSerial(id);
        return convertSuccessResult(result);
    }
    @ResponseBody
    @RequestMapping("/search_serials")
    public BaseRespVO searchSerials(SerialQo serialQo,HttpServletRequest req) throws ParseException {
        System.out.println("进入请求");
        System.out.println(serialQo);
        User user = (User) req.getSession().getAttribute("user");
        serialQo.setId(user.getId());
        List<Serial> serials = serialService.serialList(serialQo);
        return convertSuccessResult(serials);
    }

}
